package com.jhgsys.internal.peccancy.service.impl;

import com.jhgsys.internal.common.entity.FebsConstant;
import com.jhgsys.internal.peccancy.entity.PeccancyInformationFile;
import com.jhgsys.internal.peccancy.mapper.PeccancyInformationFileMapper;
import com.jhgsys.internal.peccancy.service.IPeccancyInformationFileService;
import com.jhgsys.internal.common.entity.QueryRequest;
import com.jhgsys.internal.common.utils.FebsUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Propagation;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.toolkit.StringPool;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 违章图片 Service实现
 *
 * @author wanghw
 * @date 2024-08-12 09:46:26
 */
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class PeccancyInformationFileServiceImpl extends ServiceImpl<PeccancyInformationFileMapper, PeccancyInformationFile> implements IPeccancyInformationFileService {

    /**
     * 查询（分页）
     * @author wanghw
     * @date 2024-08-12 09:46:26
     * @param request QueryRequest
     * @param peccancyInformationFile peccancyInformationFile
     * @return IPage<PeccancyInformationFile>
    */
    @Override
    public IPage<PeccancyInformationFile> findPeccancyInformationFilePage(QueryRequest request, PeccancyInformationFile peccancyInformationFile) {
        LambdaQueryWrapper<PeccancyInformationFile> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(PeccancyInformationFile::getDeletedFlg, 0);
        // TODO 设置查询条件

        Page<PeccancyInformationFile> page = new Page<>(request.getPageNum(), request.getPageSize());
        FebsUtil.pageWrapper(page, request);
        return this.page(page, queryWrapper);
    }

    /**
     * 查询（所有）
     * @author wanghw
     * @date 2024-08-12 09:46:26
     * @param peccancyInformationFile peccancyInformationFile
     * @return List<PeccancyInformationFile>
     */
    @Override
    public List<PeccancyInformationFile> findPeccancyInformationFileList(PeccancyInformationFile peccancyInformationFile) {
	    LambdaQueryWrapper<PeccancyInformationFile> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(PeccancyInformationFile::getDeletedFlg, FebsConstant.VALID);
		if(StringUtils.isNotBlank(peccancyInformationFile.getTenantId())){
            queryWrapper.eq(PeccancyInformationFile::getTenantId,peccancyInformationFile.getTenantId());
        }
        if(StringUtils.isNotBlank(peccancyInformationFile.getInformationId())){
            queryWrapper.eq(PeccancyInformationFile::getInformationId,peccancyInformationFile.getInformationId());
        }
		return this.baseMapper.selectList(queryWrapper);
    }

    /**
    * 根据ID查询
    * @author wanghw
    * @date 2024-08-12 09:46:26
    * @param id
    * @return PeccancyInformationFile
    */
    @Override
    public PeccancyInformationFile findPeccancyInformationFileById(Integer id){
        return this.baseMapper.selectById(id);
    }

    /**
     * 新增
     * @author wanghw
     * @date 2024-08-12 09:46:26
     * @param peccancyInformationFile peccancyInformationFile
     */
    @Override
    @Transactional
    public void createPeccancyInformationFile(PeccancyInformationFile peccancyInformationFile) {
        peccancyInformationFile.setCreatedTime(new Date());
        this.save(peccancyInformationFile);
    }

    /**
     * 修改
     * @author wanghw
     * @date 2024-08-12 09:46:26
     * @param peccancyInformationFile peccancyInformationFile
     */
    @Override
    @Transactional
    public void updatePeccancyInformationFile(PeccancyInformationFile peccancyInformationFile) {
        peccancyInformationFile.setUpdatedTime(new Date());
        this.saveOrUpdate(peccancyInformationFile);
    }

    /**
     * 逻辑删除
     * @author wanghw
     * @date 2024-08-12 09:46:26
     * @param peccancyInformationFile peccancyInformationFile
     * @param peccancyInformationFileIds peccancyInformationFileIds
     */
    @Override
    @Transactional
    public void deletePeccancyInformationFile(PeccancyInformationFile peccancyInformationFile,String peccancyInformationFileIds) {
        List<String> list = Arrays.asList(peccancyInformationFileIds.split(StringPool.COMMA));
        this.baseMapper.update(peccancyInformationFile,new LambdaQueryWrapper<PeccancyInformationFile>().in(PeccancyInformationFile::getPhotoFileId,list));
	}

    /**
    * 物理删除
    * @author wanghw
    * @date 2024-08-12 09:46:26
    * @param peccancyInformationFileIds peccancyInformationFileIds
    */
    @Override
    @Transactional
    public void physicallyDeletePeccancyInformationFile(String peccancyInformationFileIds) {
        List<String> list = Arrays.asList(peccancyInformationFileIds.split(StringPool.COMMA));
        LambdaQueryWrapper<PeccancyInformationFile> wapper = new LambdaQueryWrapper<>();
        wapper.in(PeccancyInformationFile::getPhotoFileId,list);
        this.remove(wapper);
    }
}
